<?php 
//$dirList = explode('/', $_SERVER['PHP_SELF']);
//require $_SERVER ["DOCUMENT_ROOT"] . "/$dirList[1]/conf/conf.php";
require "/var/www/html/step/conf/conf.php";

$mode = $_GET['mode'];
$result = 'normal';
if ($mode == 'login'){
	$user_id = $_GET ['userid'];
	$password = $_GET ['password'];
	
	$connMgr = new ConnManger($db_conf, $mem_conf);
	
	$connMng = $connMgr->getConn_step();
	
	$record = Step_admin_user_DAO::getRecord($user_id, $connMng);
	
	if ($record != null) {
		
		if ($record->getPassword() == $password){
		$pages = explode( ",", $record->getPage() );
		$page_str ="";
		$gruopList = Step_mng_group_mst_DAO::getList($connMng);
		foreach ($gruopList as $group){
			$flag = false;
			foreach ($pages as $pageid){
				$pageRecord = Step_mng_page_mst_DAO::getRecord($pageid, $connMng);
				if ($pageRecord->getGroupid() == $group->getGroupid()){
					$flag = true;
					$page_str .= $pageRecord->getPageid()."#".$pageRecord->getPagename()."#".$pageRecord->getUrl()."@";
				}
			}
			if ($flag){
				$page_str = rtrim(trim($page_str),"@");
				$page_str .= "^".$group->getGroupid()."#".$group->getGroupname()."#".$group->getImg().",";
			}
		}
		
		$page_str = rtrim(trim($page_str),",");
		
		$session = new Util_session(false,$user_id,$record->getName(),$page_str);
		
		$result = 'succLogin';
	    }else{
	    	$result = 'errLogin';
	    }
	}else {
		$result = 'errLogin';
	}
	
}

?>
<!DOCTYPE unspecified PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="css/style.css" type="text/css" rel="stylesheet" rev="stylesheet"/>

<script type="text/javascript">
function doLogin() {
	var fm = document.fm;
	if (fm.userid.value == "") {
		alert('请输入帐号');
		fm.userid.focus();
		return false;
	}
	if (fm.password.value == "") {
		alert('请输入密码');
		fm.password.focus();
		return false;
	}
	url = "./index.php?userid="+fm.userid.value+"&password="+fm.password.value+"&mode=login";
	window.location.href = url;
}
function init() {
	var fm = document.fm;
		var msg = "<?php echo $result ?>";
	 if (msg == 'succLogin') {
			fm.action = './view/pages/';
			fm.submit();
		}else if(msg == 'errLogin'){
			alert('帐号或密码错误');
			}
}
</script>

</head>
<body class="denglu02" onload="init()">
	<form  id="fm" name="fm" method="POST" action="./index.php">
	<div class="dl">
		<!-- <div class="biaoti"><img src="css/images/ico02.png" /></div> -->
		<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
		<div class="log">
			<ul class="xuzhi02">
				<br><br>
				 <li class="xz">中国人寿健步（微信）后台</li>


			</ul>
			  <ul class="deng02">
			  
				<li style=" width:100%; height:60px;">
					<p style="float:left;font-size:18px; color:#666;line-height:30px; ">用户名:</p> 
					<input id="userid" class="i-text" type="text" errormsg="用户名至少6个字符,最多18个字符！" datatype="s6-18" ajaxurl="demo/valid.jsp" maxlength="100">
				</li>
				<div style="clear:both;"></div>
		
				<li style=" width:100%; height:60px;"> 
					<p style="float:left;font-size:18px; color:#666;line-height:30px; ">密&#12288;码:</p> 
					<input id="password" class="i-text" type="password" errormsg="用户名至少6个字符,最多18个字符！" datatype="s6-18" ajaxurl="demo/valid.jsp" maxlength="100">
				</li>
				<div style="clear:both;"></div>
				
				<li style=" width:100%; height:60px;">
					<button id="logonbtn" class="btn-login02" onclick="doLogin();return false;" type="submit" > 
					<span>登&nbsp;&nbsp;&nbsp;&nbsp;录</span>
				  </button>
				</li>
			</ul>
			
		</div>
	</div>
	</form>
</body>
</html>
